#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, ans, a[N];
priority_queue<int> max2, maxDel;//两个大根堆
priority_queue<int, vector<int>, std::greater<int>> min2, minDel;//两个小根堆

int main()
{
	cin >> n;
	for (int i = 1, j = 1; i <= n; i++)
	{
		cin >> a[i];
		max2.push(a[i]);
		min2.push(a[i]);
		while (max2.top() - min2.top() > 1)
		{
			maxDel.push(a[j]);
			minDel.push(a[j]);
			j++;
			while (maxDel.size() && max2.top() == maxDel.top())
				max2.pop(), maxDel.pop();
			while (minDel.size() && min2.top() == minDel.top())
				min2.pop(), minDel.pop();
		}
		ans = max(ans, i - j + 1);
	}
	cout <<ans;
	return 0;
}